<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=7b92b3afff29988b6d4dbf9a00698ed8"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
<div class="top">
    <div id="r-result">请输入:<input type="text" id="suggestId" size="20" value="合肥" style="width:150px;" /></div>
    <div class="right">    
        <div class="points">经度<input type='text' name='lng' id='lng' value=""/></div>
        <div class="points">纬度<input type='text' id='lat' name='lat' value=""/></div>
        <div class="queren" onclick="showInfo();">确认</div>
    </div>       
</div>
<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
<div id="allmap" style="width: 560px; height:500px;"></div>
<style>
     .top {height: 30px;}
     .top input{
         height: 30px; line-height: 30px;
     }
    .top #r-result{
        float: left;
    } 
    .top .right{
        float: right;
    }
    .top .right .points{
        width: 110px;
        float: left;
        margin-right: 10px;
    }
    .top .right .points input{
        width:75px;
        display: inline-block;
    }
    .top .right .queren{
        width: 80px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background: red;
        color: #fff;
        float: right;
        margin-left: 10px;
        cursor: pointer;
    }
</style>
<script type="text/javascript">

// 百度地图API功能
    var map = new BMap.Map("allmap");
            map.centerAndZoom(new BMap.Point( "<{$lng}>" , "<{$lat}>" ), 15);
            var point = new BMap.Point( "<{$lng}>" , "<{$lat}>" );
            map.centerAndZoom(point, 15);
    var marker = new BMap.Marker(point);  // 创建标注
    map.clearOverlays();
    map.addOverlay(marker);              // 将标注添加到地图中
    marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    function showInfo(e) {
        parent.selectCallBack('data_lng', 'data_lat',document.getElementById('lng').value, document.getElementById('lat').value);
    }
    function showPoint(e) {
        document.getElementById('lat').value = e.point.lat;
        document.getElementById('lng').value = e.point.lng;
        var p = new BMap.Point(e.point.lng,e.point.lat);
        var mk = new BMap.Marker(p); 
        map.clearOverlays();
        map.addOverlay(mk); 
        mk.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    }
    map.enableScrollWheelZoom(true);
    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  //右上角，仅包含平移和缩放按钮
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN}));  //左下角，仅包含平移按钮
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));  //右下角，仅包含缩放按钮
    map.addEventListener("click", showPoint);
    function G(id) {
        return document.getElementById(id);
    }

    var ac = new BMap.Autocomplete(//建立一个自动完成的对象
            {"input": "suggestId"
                , "location": map
            });

    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;
    });

    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

        setPlace();
    });


    function setPlace() {
        map.clearOverlays();    //清除地图上所有覆盖物
        function myFun() {
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 18);
            map.addOverlay(new BMap.Marker(pp));    //添加标注
        }
        var local = new BMap.LocalSearch(map, {//智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
    }

</script>
